<template>
	<view class="content">
		<input type="text"  style="border: #007AFF 	1px solid; margin: 100rpx auto 40rpx auto; height: 60rpx; border-radius: 10rpx;" v-model="xh" />
		<button type="default" @click="go">签到</button>
		
		<ul style="margin-top: 30rpx;">
			<li v-for="(item,index) in arr">
				{{item.tm}}
			</li>
		</ul>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				xh: '',
				arr:[]
			}
		},
		onLoad() {
			let that=this;
			uni.getStorage({
				key: 'no',
				success: function (res) {
					that.xh = res.data;
					that.ls();
				}
			});
		},
		methods: {
			go(){
				let that=this;
				
				for(let i=0;i<that.arr.length;i++){
						let rq1 = new Date(that.arr[i].tm.replace("上午","").replace("下午","")).toDateString();
						let rq2 = new Date().toDateString();
						console.log(rq1,rq2)
						if(rq1==rq2){
							uni.showToast({
								title:"今天已签到"
							});
							return;
						}
				}

				uniCloud.callFunction({
					name:"qd",
					data:{"s":{"no":that.xh,"tm":new Date().toLocaleString()}},
					success() {
						uni.setStorage({
						    key: 'no',
						    data: that.xh
						});
						
						that.ls();
						uni.showToast({
							title:"签到成功"
						})
					}
				})
			},
			ls(){
				let that=this;
				uniCloud.callFunction({
					name:"qdlist",
					data:{"no":that.xh},
					success(re) {
						that.arr= re.result;
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
